<?php if (! defined('BASEPATH')) exit('No direct script access allowed');

class Comment extends CI_Controller {
	public function __construct() {
		parent::__construct();
        $this->load->model('comment_model');
	}


    function index() {
        $id = filter_input(INPUT_GET,'id',FILTER_VALIDATE_INT);
        $comment = filter_input(INPUT_POST,'comment',FILTER_SANITIZE_SPECIAL_CHARS);
        $uid = filter_input(INPUT_POST,'uid',FILTER_VALIDATE_INT);
        $uname = filter_input(INPUT_POST,'uname',FILTER_SANITIZE_STRING);
        $data = array(
            "book_id"=>$id,
            "user_id"=>!empty($uid)?$uid:0,
            "user_name"=>!empty($uname)?$uname:" ",
            "comment"=>$comment,
        );
        $time = date("Y-m-d H:i:s");
        $comment_id = $this->comment_model->insertComment($data);
        if($comment_id>1){
            header("Content-Type:text/html; charset=utf-8");
              echo <<<EOB
                                <dd>
                                    <p><a href="javascript:;">{$uname}</a> {$time} </p>
                                    <p>{$comment}</p>
                                </dd>
EOB;
        }
    }
}
?>